﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Wicresoft.Shell.Package.AppExp
{
    public class PropertyWindowManager
    {
        //APIDXX : application extension prof xsl template
        //APIDXV : application extension prof vm  template
        //APIDXT : application extension prof Txt template
        //FPIDXX : function extension prof xsl template
        //FPIDXV : function extension prof vm  template
        //FPIDXT : function extension prof Txt template
        //FPIDB : adapter type
        //FPIDD : data template
        //FPIDM : adapter template

        //non : dont need to display any property
        //normal : only display name property and read only
        //adapter : display a mobile type
        //extension : display a key value and extension type
        enum nodeType { Non, Normal, Adapter, Extension }

        private nodeType _type;
        private TreeNode _current;


        public PropertyWindowManager()
        {
            _type = nodeType.Non;
        }



        public PropertyWindowManager(TreeNode tn)
        {
            _current = tn;
            object aTreeNodeTag = tn.Tag;
            if (aTreeNodeTag == null)
            {
                _type = nodeType.Non;
            }
            else if(aTreeNodeTag.ToString().StartsWith("FPIDM"))
            {
                _type = nodeType.Adapter;
            }
            else if(aTreeNodeTag.ToString().StartsWith("FPIDX"))
            {
                _type = nodeType.Extension;
            }
            else if (aTreeNodeTag.ToString().StartsWith("APIDX"))
            {
                _type = nodeType.Extension;
            }
            else
            {
                _type = nodeType.Normal;
            }
        }

        public BasePropertyItemObject GetPropertyItemObject()
        {
            switch (_type)
            {
                case nodeType.Normal:
                    return new NormalPropertyItemObject(_current);
                    break;
                case nodeType.Adapter:
                    return new AdapterPropertyItemObject(_current);
                    break;
                case nodeType.Extension:
                    return new ExtensionPropertyItemObject(_current);
                    break;
                default:
                    return new NonPropertyItemObject();
                    break;
            }
        }
    }
}
